{% include 'QLGL/QLGL_index.html' %}

<div class="am-cf admin-main">
  {% include 'sidebar.html' %}
  <!-- content start -->
  <div class="admin-content">
    <div class="admin-content-body">
      <div class="am-cf am-padding">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">巡检业务</strong></div>
      </div>
      <div class="am-g" style="position: absolute;height: 100%;right: 0px;left: 260px;width: auto;">

        {% include 'QLGL/XJYW/QLGL_XJYW_SIDEBAR.html' %}

        <div class="am-u-sm-10" style="position: absolute;width:auto;right:0;left: 200px;overflow-y: scroll;bottom: 100px;top: 0px;">
          <!-- <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">天气情况</strong></div> -->
          <div class="am-g am-margin-top am-form-group">
            <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">维护详情</strong></div>
          </div>

            <div class="am-g am-margin-top am-form-group">
              <div class="am-u-sm-4 am-u-md-3 am-text-right">巡查内容：</div>
              <div class="am-u-sm-8 am-u-md-9" style="padding-left: 0rem;">
                  <div id=checkItem>

                  </div>
              </div>

            </div>
            <hr/>
            <div class="am-g am-margin-top">
              <div class="am-u-sm-4 am-u-md-3 am-text-right">紧急程度：</div>
                <div class="" id=urgencylevel>

                </div>
            </div>

            <hr/>
            <div class="am-g am-margin-top am-form-group">
              <div class="am-u-sm-4 am-u-md-3 am-text-right">病害详情：</div>
              <div class="am-u-sm-8 am-u-md-9" style="padding-left: 0rem;">
                  <div class="" id=disease>

                  </div>
              </div>

            </div>
            <hr/>
            <div class="am-g am-margin-top am-form-group">
              <div class="am-u-sm-4 am-u-md-3 am-text-right">桩号位置：</div>
                  <div class="" id=piledirection>

                  </div>
            </div>

            <hr/>
            <div class="am-g am-margin-top am-form-group">
              <div class="am-u-sm-4 am-u-md-3 am-text-right">备注信息：</div>
              <div class="am-u-sm-8 am-u-md-9 am-u-end" style="padding-left: 0px;">
                  <textarea rows="5" placeholder="请输入备注信息" id='txtRemark' name='txtRemark' required=""></textarea>
              </div>
            </div>
            <hr/>
            <div class="am-g am-margin-top">
              <div class="am-u-sm-4 am-u-md-3 am-text-right">媒体信息：</div>
                <input style="width:100px;height:36px;position:absolute;top:338px;left:942px;z-index: 1;opacity: 0;" name="myfile" id="f_fileXC" type="file" accept="image/*" multiple />
                <label>
                  <input id="XCXC" class="am-btn am-btn-primary am-btn-xs" type="button" value="拍照/相册" />
                </label>
            </div>


          <div class="am-g am-margin-top am-form-group">
            <ul class="am-avg-sm-2 am-avg-md-4 am-avg-lg-3 am-margin gallery-list" id='show'>
                <li></li>
            </ul>
          </div>
          <hr/>
          <div class="am-g am-margin-top am-form-group">
            <button class="am-btn am-btn-primary am-btn-xs" id='btnSeve' style="margin-left: 25%"  onclick="fromValid()">提交</button>
           </div>
        </div>
      </div>
      
      <div class="am-g am-margin-top am-form-group">
        <input type="hidden" name='txtTemperature' id='txtTemperature'>
        <input type="hidden" name='txtWeather' id='txtWeather'>
        <input type="hidden" name='txtTaskId' id='txtTaskId'>
        <input type="hidden" name='txtFileId' id='txtFileId'>
        <input type="hidden" name='txtCheckItem' id='txtCheckItem'>
        <input type="hidden" name='txtDiseaseId' id='txtDiseaseId'>
        <input type="hidden" name='txtUrgencylevel' id='txtUrgencylevel'>
        <input type="hidden" name='txtPileD' id='txtPileD'>
        <input type="hidden" name='txtPileKM' id='txtPileKM'>
        <input type="hidden" name='txtPileM' id='txtPileM'>
      </div>


    </div>
  </div>
</div>
</div>
</div>
{% include 'footer.html' %}
<!--[if lt IE 9]>
<script src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script>
<script src="http://cdn.staticfile.org/modernizr/2.8.3/modernizr.js"></script>
<script src="assets/js/amazeui.ie8polyfill.min.js"></script>
<![endif]-->

<!--[if (gte IE 9)|!(IE)]><!-->
<script src="/static/assets/js/jquery.min.js"></script>
<!--<![endif]-->
<script src="/static/assets/js/amazeui.min.js"></script>
<script src="/static/assets/js/amazeui.tree.js"></script>
<script type="text/javascript" src="/static/assets/js/layer.js"></script>
<script src="/static/assets/datatables/amazeui.datatables.min.js"></script>
<script src="/static/assets/dialog/amazeui.dialog.min.js"></script>
<link rel="stylesheet" type="text/css" href="/static/assets/css/amazeui.tree.css" />
<script src="/static/assets/js/app.js"></script>
<style type="text/css">
  .li_a {
    color: #5c5c5c;
  }
</style>
<script type="text/javascript">
  $("#collapse-nav1").addClass("am-in");
  $("#qlgl").removeClass("am-collapsed");
  $("#qlglOxjyw").css("color", "#3399CC");
  $("#qlgl").css("color", "#3399CC");
  $("#xjywOrcxc").removeClass("li_a");

  $.ajaxSetup({
    data: {csrfmiddlewaretoken: '{{ csrf_token }}' },
  });
var diseaseinfo = {{ diseaseinfo | safe }};
$(window).load(function(){
    init();
});

var init = function(){
    //存储信息
    $('#txtTemperature').val({{ temperature }});
    $('#txtWeather').val('{{ weather }}');
    $('#txtTaskId').val({{ taskid }});
    //绑定数据
    var item = diseaseinfo[0];
    $('#checkItem').append(item.checkItem);
    $('#urgencylevel').append(item.urgency);
    $('#disease').append(item.disease_name);
    $('#piledirection').append(item.pile_direction+':K'+item.pile_km+'+'+item.pile_m);
    // $('#pilekm').append(item.pile_km);
    // $('#pilem').append(item.pile_m);
    $('#txtCheckItem').val(item.param_id);
    $('#txtDiseaseId').val(item.disease_id);
    $('#txtUrgencylevel').val(item.urgency_level);
    $('#txtPileD').val(item.pile_direction);
    $('#txtPileKM').val(item.pile_km);
    $('#txtPileM').val(item.pile_m);

}

var test = function(){
    alert($('#txtTaskId').val());
}



var upimg = document.querySelector('#f_fileXC');
upimg.addEventListener('change', function(e){
    var files = this.files;
    if(files.length){
        if(checkFile(files))
        {
            uploadFiles(files);
        }
    }
});

function checkFile(files){
    for(var i=0; i<files.length; i++){
        if( !files[i].type.match(/.jpg|.jpeg|.gif|.png|.bmp/) ){  //判断上传文件格式
            AlertMSG('上传的图片格式不正确')
            return false;
        }
    }
    return true;
}

$("#XCXC").click(function () {
      $("#f_fileXC").click();
})

var fromValid = function(){
      var txtTaskId = $("#txtTaskId").val();
      var txtWeather = $("#txtWeather").val();
      var txtTemperature = $("#txtTemperature").val();
      var txtCheckItem = $("#txtCheckItem").val();
      var txtDiseaseId = $("#txtDiseaseId").val();
      var txtRemark = $("#txtRemark").val();
      var txtUrgencylevel = $("#txtUrgencylevel").val();
      var txtPileD = $("#txtPileD").val();
      var txtPileKM = $("#txtPileKM").val();
      var txtPileM = $("#txtPileM").val();
      var txtFileId = $("#txtFileId").val();


      $.ajax({
      "url":"/WHSave/",
      "data":{"txtTaskId":txtTaskId,"txtWeather":txtWeather,"txtTemperature":txtTemperature,"txtCheckItem":txtCheckItem,"txtDiseaseId":txtDiseaseId,"txtRemark":txtRemark,"txtUrgencylevel":txtUrgencylevel,"txtPileD":txtPileD,"txtPileKM":txtPileKM,"txtPileM":txtPileM,"txtFileId":txtFileId},
      "datatype":"json",
      "type":"post",
      "async":"false"
      }).success(function(data){
        if (data.status == 1) {
          alert("保存成功！")
          
          window.location='/QLXJ_XJYW_RCJC/'


        } else {
          AlertMSG(data.message)
        }
      }).error(function(data){
        AlertMSG("保存失败！")
      });

}
var uploadFiles = function(files){
    var form_data = new FormData();
    for(var i=0; i< files.length; i++){
        form_data.append("myfile" , files[i] );
    }
    // 提交ajax的请求

    $.ajax({
        url:"/uploadFile_XC/",
        type:'POST',
        data: form_data,
        processData: false,  // tell jquery not to process the data
        contentType: false, // tell jquery not to set contentType
        success: function(result) {
            console.log(result.data)
            if (result.status == 1){
                var show = $("#show");
                // show.css("display","block");
                var html = '',ids = '';
                var fileIds = $('#txtFileId');
                for(var i = 0 ;i<result.data.length;i++){
                    var f = result.data[i];
                    html += '<li><img class="am-img-thumbnail am-img-bdrs" src="'+f.file_url+'" alt="img"></li>';
                    ids += f.file_id+'|'
                    // console.log(f.file_url);
                }
                fileIds.val(ids);
                show.html(html);
            }
        }
    });
}
var AlertMSG=function(msg){
    AMUI.dialog.alert({ title: '错误提示', content: msg, onConfirm: function() { console.log('close'); } });
}
</script>

</body>

</html>